﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace ProjectSem40701
{
    public partial class PasswordRecovery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGetUser_Click(object sender, EventArgs e)
        {
            try
            {
                MembershipUser u = Membership.GetUser(this.txtUserName.Text.Trim());
                if (u != null)
                {
                    this.ltrSecQues.Text = u.PasswordQuestion;
                    this.myMultiview.ActiveViewIndex = 1;
                }
            }
            catch
            {
               //bao loi
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                MembershipUser u = Membership.GetUser(this.txtUserName.Text.Trim());
                if (u != null && this.txtSecurityAnswer.Text.Trim() != "")
                {
                    string newPassword = u.ResetPassword(this.txtSecurityAnswer.Text.Trim());
                    this.myMultiview.ActiveViewIndex = 2;
                    Session["newPwd"] = newPassword;
                    this.lblNewPwd.Text = newPassword;
                    Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
                    FormsAuthentication.SetAuthCookie(u.UserName.Trim(), false);
                }
            }
            catch
            { 
                //bao loi
            }
        }
    }
}
